package config

import (
	"github.com/BurntSushi/toml"
	"go.uber.org/zap"
	"os"
)

type Viewer struct {
	Title       string
	Description string
	Logo        string
	Navigation  []string
	Gitee       string
	CsdnURL     string
	Avatar      string
	UserName    string
	UserDesc    string
	HtmlName    []string
}

type SystemConfig struct {
	AppName         string
	Version         float32
	CurrentDir      string
	CdnURL          string
	QiniuAccessKey  string
	QiniuSecretKey  string
	Valine          bool
	ValineAppid     string
	ValineAppKey    string
	ValineServerURL string
	JwtSecret       string
	IP              string
	Port            string
}

type TomlConfig struct {
	Viewer Viewer
	System SystemConfig
}

var Cfg *TomlConfig

func LoadConfig() {
	Cfg = new(TomlConfig)
	var err error
	Cfg.System.CurrentDir, err = os.Getwd()
	if err != nil {
		zap.S().Error("读取当前路径失败")
		panic(err)
	}
	if _, err = toml.DecodeFile("config/config.toml", &Cfg); err != nil {
		zap.S().Error("读取config.toml失败")
		panic(err)
	}
}
